<template>
    <div class="carousel">
        <div class="carousel-container" :style="{ transform: `translateX(-${currentIndex * 100}%)` }">
            <div v-for="(slide, index) in slides" :key="index" class="carousel-slide">
                <img :src="slide.image" :alt="slide.title" />
                <div class="slide-content">
                    <h2>{{ slide.title }}</h2>
                    <p>{{ slide.description }}</p>
                </div>
            </div>
        </div>
        <div class="carousel-dots">
            <span 
                v-for="(_, index) in slides" 
                :key="index"
                :class="{ active: currentIndex === index }"
                @click="setSlide(index)"
            ></span>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            currentIndex: 0,
            slides: [
                {
                    image: 'https://www.ipdodo.com/news/wp-content/themes/Relive-Pro/timthumb.php?src=https://www.ipdodo.com/news/wp-content/uploads/2024/11/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20241128185158-1024x458.jpg&w=800&h=600&zc=1&q=100',
                    title: '全球代理服务',
                    description: '覆盖200+国家地区的优质IP资源'
                },
                {
                    image: 'https://www.ipdodo.com/news/wp-content/themes/Relive-Pro/timthumb.php?src=https://www.ipdodo.com/news/wp-content/uploads/2024/11/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20241128185158-1024x458.jpg&w=800&h=600&zc=1&q=100',
                    title: '稳定高效',
                    description: '99.9%可用性保证'
                },
                {
                    image: 'https://www.ipdodo.com/news/wp-content/themes/Relive-Pro/timthumb.php?src=https://www.ipdodo.com/news/wp-content/uploads/2024/11/%E5%BE%AE%E4%BF%A1%E6%88%AA%E5%9B%BE_20241128185158-1024x458.jpg&w=800&h=600&zc=1&q=100',
                    title: '专业支持',
                    description: '7*24小时技术支持服务'
                }
            ]
        }
    },
    mounted() {
        this.startAutoSlide()
    },
    beforeDestroy() {
        this.stopAutoSlide()
    },
    methods: {
        setSlide(index) {
            this.currentIndex = index
        },
        startAutoSlide() {
            this.timer = setInterval(() => {
                this.currentIndex = (this.currentIndex + 1) % this.slides.length
            }, 5000)
        },
        stopAutoSlide() {
            clearInterval(this.timer)
        }
    }
}
</script>

<style scoped>
.carousel {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.carousel-container {
    display: flex;
    transition: transform 0.6s ease-in-out;
    height: 100%;
    width: 100%;
}

.carousel-slide {
    flex: 0 0 100%;
    position: relative;
    height: 100%;
    width: 100%;
}

.carousel-slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
}

.slide-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 30px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    color: white;
}

.slide-content h2 {
    margin: 0 0 8px 0;
    font-size: 28px;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.slide-content p {
    margin: 0;
    font-size: 18px;
    opacity: 0.9;
}

.carousel-dots {
    position: absolute;
    bottom: 25px;
    right: 25px;
    display: flex;
    gap: 10px;
}

.carousel-dots span {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.carousel-dots span.active {
    background: white;
    transform: scale(1.3);
}

@media (max-width: 768px) {
    .carousel {
        height: 460px;
    }
}
</style> 